//
//  UIAlertController+WF.m
//  WisdomFarm
//
//  Created by sky on 2017/12/7.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "UIAlertController+WF.h"

@implementation UIAlertController (WF)

+ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle actionTitles:(NSArray<NSString *> *)titles handler:(void (^)(NSInteger))handler {
    UIAlertController *controller = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:preferredStyle];
    __block NSInteger index = 0;
    for (NSString *title in titles) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            handler(index);
            index ++;
        }];
        [controller addAction:action];
    }
    return controller;
}

@end
